package com.bonc.rms.service.impl;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.bonc.rms.dao.LoginDao;
import com.bonc.rms.entity.UserEntity;
import com.bonc.rms.jpa.UserJpa;
import com.bonc.rms.jpa.UserRepository;
import com.bonc.rms.service.LoginService;

@Service(value = "loginServiceImpl")
public class LoginServiceImpl implements LoginService {
	@Autowired
	LoginDao loginDao;
	@Autowired
	UserRepository userRepository;

	/**
	 * 返回参数含义： 0代表无该用户，1代表登录成功，-1代表密码错误
	 */
	@Override
	public List<Object> login(String name, String password) {
		
		List<Object> list = new ArrayList<Object>();		
		UserEntity userEntity = userRepository.findUserEntityByUserName(name);		
		if(userEntity == null){
			list.add(0);			
		}
		else if (password.equals(userEntity.getPasswd())) {
			list.add(1);
			list.add(userEntity);
		} else {
			list.add(-1);			
		}		
		return list;
	}

	@Override
	public List<Map<String, Object>> getResume() {
		return loginDao.getResume() == null ? new ArrayList<Map<String, Object>>() : loginDao.getResume();
	}

	@Override
	public Map<String, Object> getDashBoardData() {
		Map<String, Object> dashBordDataMap = new HashMap<>();
		dashBordDataMap.put("degree", loginDao.getByTerm("degree"));
		dashBordDataMap.put("gender", loginDao.getByTerm("gender"));
		dashBordDataMap.put("age", loginDao.getByRange("age"));
		dashBordDataMap.put("workingExperience", loginDao.getByRange("workingExperience"));
		return dashBordDataMap;
	}

}
